/**
 * Aibton.com Inc.
 * Copyright (c) 2016-2017 All Rights Reserved.
 */
package com.aibton.example.controller;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.aibton.example.config.ConstantKey;
import com.aibton.framework.api.IApiEngine;
import com.aibton.framework.api.data.EngineContext;
import com.aibton.framework.data.BaseResponse;
import com.aibton.framework.util.AssertUtils;

/**
 * @author huzhihui
 * @version $: v 0.1 2017 2017/7/28 14:47 huzhihui Exp $$
 */
@RestController
public class GatewayController {

    private static final Logger LOGGER = LoggerFactory.getLogger(GatewayController.class);

    @Autowired
    private IApiEngine          iApiEngine;

    @RequestMapping(value = "gateway")
    public Object doExcute(HttpServletRequest request, String api, String data) {
        AssertUtils.isNotEmpty(LOGGER, api, ConstantKey.API_NOT_NULL);
        AssertUtils.isNotEmpty(LOGGER, data, ConstantKey.API_DATA_NOT_NULL);
        EngineContext engineContext = new EngineContext();
        engineContext.setApiUrl(api);
        engineContext.setRequestData(data);
        engineContext.setRequest(request);
        BaseResponse baseResponse = iApiEngine.run(engineContext);
        return baseResponse;
    }
}
